//
//  DrawPurseViewController.m
//  MyWallet
//
//  Created by 小肥羊 on 15/7/17.
//  Copyright (c) 2015年 小肥羊. All rights reserved.
//

#import "DrawPurseViewController.h"

@interface DrawPurseViewController ()

@end

@implementation DrawPurseViewController

#pragma mark - Set
- (void)setDrawDate:(NSDate *)drawDate
{
    _drawDate = drawDate;
    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    NSString *locationString=[dateformatter stringFromDate:_drawDate];
    [self.changeDateButton setTitle:locationString forState:UIControlStateNormal];
}


#pragma mark - 初始化
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.selectDateView = [[SelectDateView alloc] initWithDelegate:self];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.moneyLabel setText:[[NSString alloc] initWithFormat:@"$ %.2f",[TotalAssets sharedManager].walletMoney]];
    self.drawDate = [NSDate date];
    [self.changeDateButton.layer setCornerRadius:kNomalRadius];
    self.moneyForSelectView.contents = [[NSMutableArray alloc] initWithArray:Macro_MoneyForDraw];
    self.moneyFor = Macro_MoneyForDraw[0];
    self.moneyForSelectView.delegate = self;
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.moneyText becomeFirstResponder];
}

#pragma mark - 完成
- (IBAction)finishDrawPurse:(UIBarButtonItem *)sender {
    float money = [self.moneyText.text floatValue];
    if (money == 0.0f) {
        UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"。。。" message:@"你什么都没做" delegate:nil cancelButtonTitle:@"是吗" otherButtonTitles:nil];
        [alter show];
    } else {
        if ([[TotalAssets sharedManager] drawWallemoney:money RecordDate:self.drawDate MoneyFor:self.moneyFor Remarks:self.remarkLabel.text]) {
            [self.navigationController popViewControllerAnimated:YES];
        } else {
            UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"穷逼" message:@"没那么多钱啊" delegate:nil cancelButtonTitle:@"好吧" otherButtonTitles:nil];
            [alter show];
        }
    }
}

#pragma mark - 编辑结束
- (IBAction)finishEditTextFiled:(UITextField *)sender {
    
}

#pragma mark - 点击背景
- (IBAction)touchBackView:(UITapGestureRecognizer *)sender {
    [self.view endEditing:YES];
}

#pragma mark - 修改时间
- (IBAction)changeDate:(UIButton *)sender {
    [self.view endEditing:YES];
    [ActionView showView:self.selectDateView direction:PopViewDirectionStyleCenter];
}

#pragma mark - 时间选择代理
- (void)selectDate:(SelectDateView *)picker
{
    self.drawDate = picker.datePicker.date;
    [[NSNotificationCenter defaultCenter] postNotificationName:CLOESNOTICE object:picker];
}
- (void)cancelSelect:(SelectDateView *)picker
{
    [[NSNotificationCenter defaultCenter] postNotificationName:CLOESNOTICE object:picker];
}

#pragma mark - XFYSelectScrollView代理
- (void)operation:(XFYSelectScrollView *)selectView Button:(UIButton *)button AtIndex:(NSInteger)index
{
    [self.view endEditing:YES];
    self.moneyFor = button.titleLabel.text;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
